<template>
  <div class="container">
    <div class="background"></div>
    <div class="distribution">
      <div class="panel">
        <div class="flex pad-l-14 pad-r-14">
          <img class="panel__avatar" v-if="memberInfo.avatar" :src="memberInfo.avatar" alt="">
          <div class="pad-t-10 pad-l-10 font-13 font-w">{{memberInfo.nickname}}</div>
        </div>
        <div class="mar-t-30 mar-b-20 flex flex-between pad-l-14 pad-r-14">
          <div>
            <div class="font-12 font-color-6">可提现佣金(元)</div>
            <div class="font-24 font-w mar-t-5">{{memberStat.availableAmount}}</div>
          </div>
          <div class="wallet__btn" @click="$pt.navigateTo({url:'/pages/personal/wallet/cash/main'})">提现</div>
        </div>
        <div class="total-row flex flex-between pad-l-14 pad-r-14">
          <div>
            <span class="font-12 font-color-6">累计佣金：</span>
            <span class="font-18">{{memberStat.totalAmount}}</span>
          </div>
          <div class="dividing-line"></div>
          <div @click="$pt.navigateTo({url:'/pages/personal/wallet/cash-manage/main?record=1'})">
            <span class="font-12 font-color-6">待结算佣金：</span>
            <span class="font-18">{{memberStat.unavailableAmount}}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="labelcell">
      <div class="cell flex flex-between" @click="$pt.navigateTo({url:'/pages/personal/my-distribution/distribution-record/main'})">
        <div class="v-align-c">
          <img class="width-14 height-19" v-if="fileSpace" :src="fileSpace + '/images/my-distribution-cell-1.png'" alt="">
          <span class="mar-l-6">分销记录</span>
        </div>
        <div>
          <van-icon name="arrow" color="#999999" size="15px" />
        </div>
      </div>
      <div class="cell flex flex-between" @click="$pt.navigateTo({url:'/pages/personal/wallet/cash-manage/main?record=0'})">
        <div class="v-align-c">
          <img class="width-14 height-19" v-if="fileSpace" :src="fileSpace + '/images/my-distribution-cell-2.png'" alt="">
          <span class="mar-l-6">提现记录</span>
        </div>
        <div>
          <van-icon name="arrow" color="#999999" size="15px" />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { statMemberCommission } from '@/api/personal'
import { getMemberInfo } from '@/api/home'
export default {
  data() {
    return {
      memberStat: {},
      memberInfo: {}
    }
  },
  onLoad() {
    // 初始化data
    Object.assign(this.$data, this.$options.data())
  },
  mounted() {
    this.getMemberInfo()
    this.statMemberCommission()
    let appInfo = this.$pt.getStorageSync('appInfo')
    this.$pt.setNavigationBarTitle({
      title: appInfo.myCommissionAlias || '我的分销'
    })
  },
  methods: {
    getMemberInfo() {
      getMemberInfo(this.getCustomerId).then(response => {
        if (response.isError) return
        this.memberInfo = response.data
      })
    },
    statMemberCommission() {
      this.$pt.showLoading()
      statMemberCommission({memberId: this.getCustomerId}).then(response => {
        this.$pt.hideLoading()
        if (response.isError) return
        this.memberStat = response.data
      })
    }
  }
}
</script>
<style lang="less" scoped>
.background{
  background: #ffd600;
  height: 95px;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.distribution{
  position: relative;
  .panel{
    margin-top: 30px;
    margin-left: 15px;
    margin-right: 15px;
    &__avatar{
      width: 60px;
      height: 60px;
      border-radius: 50%;
      margin-top: -23px;
    }
    .total-row{
      height: 60px;
      background: #fafafa;
      border-bottom-left-radius: 10px;
      border-bottom-right-radius: 10px;
    }
    .wallet__btn{
      width: 75px;
      height: 32px;
      line-height: 32px;
      background: #ffd800;
      font-size: 15px;
      font-weight: bold;
      border-radius: 20px;
      text-align: center;
    }
  }
}
.labelcell{
  background: white;
  .cell{
    height: 58px;
    padding: 0 15px;
    position: relative;
    &::after{
      content: "";
      border: 1px solid #f3f3f3;
      position: absolute;
      width: calc(100% - 50px);
      bottom: 0;
      left: 25px
    }
  }
  .cell:last-child{
    &::after{
      border: unset;
    }
  }
}
.dividing-line{
  width: 1px;
  height: 17px;
  background: #d9d9d9;
}
</style>
